package com.fa4j.system.account.repository.impl;

import com.fa4j.common.data.repository.impl.BaseRepositoryImpl;
import com.fa4j.common.web.model.AppType;
import com.fa4j.system.account.model.Account;
import com.fa4j.system.account.repository.AccountRepository;
import com.fa4j.system.account.repository.mapper.AccountMapper;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * 系统账号 持久化接口 实现
 *
 * @since 2025-05-06 16:16:26
 */
@Repository
public class AccountRepositoryImpl extends BaseRepositoryImpl<AccountMapper, Account> implements AccountRepository {

    @Override
    public Optional<Account> findByUsername(AppType appType, String username) {
        return super.lambdaQuery()
                .eq(Account::getAppType, appType)
                .eq(Account::getUsername, username)
                .oneOpt();
    }

    @Override
    public Optional<Account> findByPhone(AppType appType, String phone) {
        return super.lambdaQuery()
                .eq(Account::getAppType, appType)
                .eq(Account::getPhone, phone)
                .oneOpt();
    }

    @Override
    public Optional<Account> findByEmail(AppType appType, String email) {
        return super.lambdaQuery()
                .eq(Account::getAppType, appType)
                .eq(Account::getEmail, email)
                .oneOpt();
    }
}
